package com.bnz.service;

import com.bnz.entity.User;
import com.bnz.mapper.UserMapper;
import com.bnz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

// 注入service容器
@Service
// 添加事务注解（事务一般写在service）
@Transactional
public class UserServiceImpl implements UserService {

    // 从spring容器中获取bean
    @Autowired
    private UserMapper userMapper;

    // 1、转账
    @Override
    public void transfer(int outNo, int inNo, double money) {
        // 1.1、转出的账户
        userMapper.update(outNo,money);
        // 制造一个异常用来测试事务
        int i = 1/0;
        // 1.2、收钱账户
        userMapper.update(inNo,-money);
    }
}
